home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: kanze@gabi.gabi-soft.fr (J. Kanze)
- Newsgroups: comp.std.c++
- Subject: Re: Time representations
- Date: 16 Feb 1996 09:04:41 PST
- Organization: GABI Software, Sarl.
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <KANZE.96Feb16125933@gabi.gabi-soft.fr>
- References: <4emq2k$ecu@news.duke.edu> <tuivhsd7fn.fsf@nemo.bedford.waii.com>
- <4ere1v$mss@news.duke.edu> <4fddsi$md@hollywood.cinenet.net>
- <4fovvr$f1d@blackice.winternet.com>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: 16 Feb 1996 11:59:33 GMT
- In-Reply-To: jdege@winternet.com's message of 13 Feb 1996 09:54:28 PST
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMSS5UUy4NqrwXLNJAQEbVAH+JLCBxav/4dGDmBbuBQ4rtXtpoDjwv1Kp
- Refbih7x1/mdPvQY4V/+cCG/hja3EqcjBL6y7sPf1pV3eNNN9vMtjA==
- =SFvE
- Originator: austern@isolde.mti.sgi.com
-
- In article <4fovvr$f1d@blackice.winternet.com> jdege@winternet.com (Jeff
- Dege) writes:
-
- > An off-the-wall question:
- >
- > time() returns a time_t, localtime() converts this to a struct tm with
- > local time values, gmtime() converts this to a struct tm with GMT values,
- > mktime() converts this back to a time_t, but _which_ struct tm does
- > it convert back?
-
- According to ISO 9899 (included by reference in the C++ standard): "The
- mktime function converts the broken-down time, expressed as
- _local_time_..." (Emphesis added.)
-
- > i.e.,
- >
- > time_t t0 = time(NULL);
- >
- > struct tm T1 = *localtime(&t0);
- > struct tm T2 = *gmtime(&t0);
- >
- > time_t t1 = mktime(&T1);
- > time_t t2 = mktime(&T2);
- >
- > Either t0 == t1 or t0 == t2, but which is true?
-
- t0 == t1.
-
- > Does the standard specify?
- > If so, how many compilers get it right?
-
- Given that this is a standard C function, and has been around for a
- while, I would imagine that all of them do. Particularly as the
- function author has to make a choice in the matter, and there is no
- particular motivation for a wrong choice.
-
- More problematic is using mktime to correct the time, which it also
- supports. For example:
-
- time_t t0( time( NULL ) ) ;
- struct tm t = *localtime( &t0 ) ;
- t.tm_min += 60 ;
- mktime( &t ) ;
-
- The last call to mktime should `correct' t so that the struct contains
- the correct entry for the time one hour after that returned by time. I
- often wonder how well this has been tested, say when the original time
- was 10 minutes before midnight Dec. 31, or before a change in time due
- to switching between summer time and winter time.
- --
- James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
- GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
- Conseils, itudes et rialisations en logiciel orienti objet --
- -- A la recherche d'une activiti dans une region francophone
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
- in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
-